﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using fsw.Common;

namespace fsw.Web.Manager
{
    public partial class Manager_Pwd : Web.UI.ManagePage
    {
        protected Model.Admin model_admin;
        protected void Page_Load(object sender, EventArgs e)
        {
            model_admin = GetAdminInfo();
            if (DTRequest.IsPost())
            {
                Response.Write(ManagerPwd());
                Response.End();
            }
        }
        private string ManagerPwd()
        {
            BLL.Admin bll = new BLL.Admin();
            Model.Admin model = bll.GetModel(model_admin.Id);            
            string PassWord = DTRequest.GetFormString("t0");///原密码
            string NewPassWord = DTRequest.GetFormString("t1");//新密码
            string RePassWord = DTRequest.GetFormString("t2");//重新密码
            if (model.PassWord != Utils.MD5(PassWord))
            {
                return JsonErr("error", "旧密码不正确！");
            }
            if (NewPassWord != RePassWord)
            {
                return JsonErr("error", "两次密码不一致！");
            }
            model.PassWord = Utils.MD5(NewPassWord);

            if (!bll.Update(model))
            {
                return JsonErr("error", "保存过程中发生错误！");
            }
            Session[DTKeys.SESSION_ADMIN_INFO] = null;
            return JsonErr("success", "密码修改成功！");
        }
    }
}